package com.example.administrator.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.administrator.myapplication.uilts.PeiZhiActivity;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by 董豪华 on 2017/1/6.
 */
public class WeekAcitivity extends AppCompatActivity {
    private TextView nameben;
    private TextView dateben;
    private TextView weekthben;
    private TextView week_health;
    private TextView jobben;
    private TextView loveben;
    private TextView moneyben;
    private TextView workben;
    String xingzuo;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.weekxingzuo_item);
        Intent intent = getIntent();
        xingzuo = intent.getStringExtra("xingzuo");
        initdata();
        shujufanhui(xingzuo);
    }
    public void shujufanhui(String consName){
        String url = "http://web.juhe.cn:8080/constellation/getAll?consName="+consName+"&type=week&key=4ab3d0b2232c72d9c3dc4747baf8cf4f";
        StringRequest request = new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                jieximing(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        PeiZhiActivity.mrequestQueue.add(request);
    }
    private void initdata() {
        nameben = (TextView) findViewById(R.id.nameben);
        dateben = (TextView) findViewById(R.id.dateben);
        weekthben = (TextView) findViewById(R.id.weekthben);
        week_health = (TextView) findViewById(R.id.week_health);
        jobben = (TextView) findViewById(R.id.jobben);
        loveben = (TextView) findViewById(R.id.loveben);
        moneyben = (TextView) findViewById(R.id.moneyben);
        workben = (TextView) findViewById(R.id.workben);
    }
    /*本周或下周*/
    public void jieximing(String response){
        try {
            JSONObject jsonObject1 = new JSONObject(response);
            String name = jsonObject1.optString("name");
            String date = jsonObject1.optString("date");
            String weekth = jsonObject1.optString("weekth");
            String health = jsonObject1.optString("health");
            String job = jsonObject1.optString("job");
            String love = jsonObject1.optString("love");
            String money = jsonObject1.optString("money");
            String work = jsonObject1.optString("work");
            String resultcode = jsonObject1.optString("resultcode");
            String error_code = jsonObject1.optString("error_code");
            nameben.setText(name);
            dateben.setText(date);
            weekthben.setText(weekth);
            week_health.setText(health);
            jobben.setText(job);
            loveben.setText(love);
            moneyben.setText(money);
            workben.setText(work);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
